use strict;
use warnings;

package JasPerl::JSTL::Core::WhenTag;
use parent qw(JasPerl::JSTL::Core::ConditionalTagSupport);

use JasPerl::JSTL::Core::Exceptions;
use JasPerl::Util::Boolean;

my $PARENT_CLASS = 'JasPerl::JSTL::Core::ChooseTag';

sub set_test {
    $_[0]->{test} = JasPerl::Util::Boolean->from($_[1]);
}

sub condition {
    my $self = shift;
    my $parent = $self->find_ancestor_isa($PARENT_CLASS)
        or JasPerl::JSTL::Core::Exception->throw('WHEN_OUTSIDE_CHOOSE');
    return $self->{test} && !$parent->done();
}

1;
